<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="description" content="Neon Admin Panel">
	<meta name="author" content="">
	
	<title>Green Soil | Login</title>
	

	<link rel="stylesheet" href="static/css/jquery-ui-1.10.3.custom.min.css">
	<link rel="stylesheet" href="static/css/entypo.css">
	<link rel="stylesheet" href="static/css/css.css">
	<link rel="stylesheet" href="static/css/bootstrap.css">
	<link rel="stylesheet" href="static/css/neon-core.css">
	<link rel="stylesheet" href="static/css/neon-theme.css">
	<link rel="stylesheet" href="static/css/neon-forms.css">
	<link rel="stylesheet" href="static/css/custom.css">

	<script src="static/js/jquery-1.11.0.min.js"></script>

	<!--[if lt IE 9]><script src="assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

	<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
	<!--[if lt IE 9]>
		<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
		<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
	
	
</head>
<body class="page-body login-page login-form-fall" data-url="http://neon.dev">


<!-- This is needed when you send requests via Ajax --><script type="text/javascript">
var baseurl = '';
</script>

<div class="login-container">
	
	<div class="login-header login-caret">
		
		<div class="login-content">
			
			<a href="index.html" class="logo">
				<img src="static/picture/green.png" width="280" alt="">
			</a>
			
			<p class="description" >亲爱的用户，请在下方区域输入用户名和密码！</p>
			
			<!-- progress bar indicator -->
			<div class="login-progressbar-indicator">
				<h3>43%</h3>
				<span>logging in...</span>
			</div>
		</div>
		
	</div>
	
	<div class="login-progressbar">
		<div></div>
	</div>
	
	<div class="login-form">
		
		<div class="login-content">
			
			<div class="form-login-error">
				<h3>Invalid login</h3>
				<p>Enter <strong>demo</strong>/<strong>demo</strong> as login and password.</p>
			</div>
			
			<form method="post" role="form" id="form_login">
				
				<div class="form-group">
					
					<div class="input-group">
						<div class="input-group-addon">
							<i class="entypo-user"></i>
						</div>
						
						<input type="text" class="form-control" name="username" id="username" placeholder="手机号/邮箱" autocomplete="off">
					</div>
					
				</div>
				
				<div class="form-group">
					
					<div class="input-group">
						<div class="input-group-addon">
							<i class="entypo-key"></i>
						</div>
						
						<input type="password" class="form-control" name="password" id="password" placeholder="密码" autocomplete="off">
					</div>
				
				</div>
				
				<div >
					<button type="submit" class="btn btn-default btn-block btn-login" id="my">
						<a  class="form-group">登录</a>
					</button>
				</div>
				

			</form>
			
			
			<div class="login-bottom-links">
				
				<a href="register.html" class="link">注册新账户</a>
				
				<br>
				
				<a href="#">ToS</a>  - <a href="#">Privacy Policy</a>
				
			</div>
			
		</div>
		
	</div>
	
</div>


	<!-- Bottom Scripts -->
	<script src="static/js/main-gsap.js"></script>
	<script src="static/js/jquery-ui-1.10.3.minimal.min.js"></script>
	<script src="static/js/bootstrap.js"></script>
	<script src="static/js/joinable.js"></script>
	<script src="static/js/resizeable.js"></script>
	<script src="static/js/neon-api.js"></script>
	<script src="static/js/jquery.validate.min.js"></script>
	<script src="static/js/neon-login.js"></script>
	<script src="static/js/neon-custom.js"></script>
	<script src="static/js/neon-demo.js"></script>
	<script src="https://cdn.bootcss.com/crypto-js/3.1.9-1/crypto-js.min.js"></script>
<script src="./gethost.js" type="text/javascript"></script>
	<script>


		var os = function() {
			var ua = navigator.userAgent,
					isWindowsPhone = /(?:Windows Phone)/.test(ua),
					isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone,
					isAndroid = /(?:Android)/.test(ua),
					isFireFox = /(?:Firefox)/.test(ua),
					isChrome = /(?:Chrome|CriOS)/.test(ua),
					isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox && /(?:Tablet)/.test(ua)),
					isPhone = /(?:iPhone)/.test(ua) && !isTablet,
					isPc = !isPhone && !isAndroid && !isSymbian;
			return {
				isTablet: isTablet,
				isPhone: isPhone,
				isAndroid: isAndroid,
				isPc: isPc
			};
		}();

		if(os.isAndroid || os.isPhone||os.isTablet) {
			alert("该系统不支持移动设备,请使用电脑登录！")
			window.location.href="index.html";
		}


		function encryptByDES(message, key){
    		var keyHex = CryptoJS.enc.Utf8.parse(key);
    		var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
        		mode: CryptoJS.mode.ECB,
        		padding: CryptoJS.pad.Pkcs7
    		});
    		return encrypted.ciphertext.toString();
		}
		
		$("#my").on("click",function(){
			var username = $("#username").val();
			var password = $("#password").val();

			if(username == null || username == ""){
				alert("邮箱或用户名不能为空");
				return false;
			}
			if(password == null || password == ""){
				alert("密码不能为空");
				return false;
			}

			if(username.length>20){
				alert("姓名长度过长！");
				return false;
			}

			if(username.length>25){
				alert("密码长度过长！");
				return false;
			}
			password=encryptByDES(password,"key");



			$.ajax({
				type:"POST",
				contentType:"application/x-www-form-urlencoded",
				url:"http://"+g_host+"/user/login",
				data:{
					"username":username,
					"password":password
				},
				xhrFields:{withCredentials:true},
				success:function(data){
					if(data.status == "success"){
						var token = data.data;
						window.localStorage["token"] = token;
						window.location.href="system-index.html";
					}else{
						alert("登陆失败，原因为"+data.data.errMsg);
					}
				},
				error:function(data){
					window.location.href="500.html";
				}
			});
			return false;
		});

	</script>

</body>
</html>